package net.framework.smc.demo.service;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;


/**
 * @authore zyx
 * @date 2018/7/2 15:54
 */
@Slf4j
@Component
@EnableScheduling
public class SendService {

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void send(String msg){
        ListenableFuture future = kafkaTemplate.send("test0622", msg);
        future.addCallback(o -> System.out.println("send-消息发送成功：" + msg), throwable -> System.out.println("消息发送失败：" + msg));

    }
}
